#include "ztcpsocket.h"

ZTcpSocket::ZTcpSocket(QObject *parent) : QTcpSocket(parent)
{

}

void ZTcpSocket::connectServer()
{
    this->connectToHost(QHostAddress("39.96.48.17"),12345);
}

void ZTcpSocket::sendTcpData(QString name,QString data,QDateTime current)
{
    m_TcpData.setIp(this->localAddress().toString());
    m_TcpData.setPort(this->localPort());
    m_TcpData.setName(name);
    m_TcpData.setTime(current);
    m_TcpData.setContent(data);
    QDataStream out(this);
    out << m_TcpData;
}

ZTcpData ZTcpSocket::readAllData()
{
    //QByteArray out;
    QDataStream in(this);
    in >> m_TcpData;
    //QString time = m_TcpData.Time().toString(" yyyy-MM-dd hh:mm:ss");
    //out = "\n"+m_TcpData.Name().toUtf8()+time.toUtf8()+":\n"+m_TcpData.Content().toUtf8();
    return m_TcpData;
}
